package com.upcode.weighing.vo.resp;

import com.upcode.weighing.base.domain.BaseEntity;
import com.upcode.weighing.util.DateUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;

/**
 * <p>
 * 检测点信息
 * </p>
 *
 * @author alex
 * @since 2024-07-21
 */
@ApiModel(value = "检测点信息", description = "")
public class DetectPointRespVo extends BaseEntity {

    private static final long serialVersionUID = 1L;

    private String id;

    /**
     * 检测点名称
     */
    @ApiModelProperty("检测点名称")
    private String name;

    /**
     * 检测点编号
     */
    @ApiModelProperty("检测点编号")
    private String pointNo;

    /**
     * 当前状态(0离线1在线)
     */
    @ApiModelProperty("当前状态(0离线1在线)")
    private Integer status;

    /**
     * 检测设备类型(1便携式2车载)
     */
    @ApiModelProperty("检测设备类型(1便携式2车载)")
    private Integer deviceType;

    /**
     * 当前登录人
     */
    @ApiModelProperty("当前登录人")
    private String loginingUser;

    /**
     * 当前执法单位
     */
    @ApiModelProperty("当前执法单位")
    private String detectDept;

    /**
     * 当前在线时长(单位s)
     */
    @ApiModelProperty("当前在线时长(单位s)")
    private Long onlineDuration = 0l;

    /**
     * 最后一次离线时长(单位s)
     */
    @ApiModelProperty("最后一次离线时长(单位s)")
    private Long offlineDuration = 0l;

    /**
     * 最后一次离线时间
     */
    @ApiModelProperty("最后一次离线时间")
    private LocalDateTime lastOfflineTime;

    /**
     * 最后一次离线时间
     */
    @ApiModelProperty("最后一次离线时间")
    private LocalDateTime onlineStartTime;
    /**
     * 最后一次离线时间
     */
    @ApiModelProperty("最后一次心跳上传时间")
    private LocalDateTime lastHeartbeatTime;
    /**
     * 当前使用位置
     */
    @ApiModelProperty("当前使用位置")
    private String location;
    /**
     * 检测点名称
     */
    @ApiModelProperty("检测点纬度")
    private BigDecimal lat;

    /**
     * 检测点编号
     */
    @ApiModelProperty("检测点经度")
    private BigDecimal lng;

    @ApiModelProperty("上传的authCode")
    private String uploadAuthCode;
    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPointNo() {
        return pointNo;
    }

    public void setPointNo(String pointNo) {
        this.pointNo = pointNo;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getDeviceType() {
        return deviceType;
    }

    public void setDeviceType(Integer deviceType) {
        this.deviceType = deviceType;
    }

    public String getDetectDept() {
        return detectDept;
    }

    public void setDetectDept(String detectDept) {
        this.detectDept = detectDept;
    }

    public Long getOnlineDuration() {
        if (status == 1) {
            onlineDuration = Duration.between(onlineStartTime, LocalDateTime.now()).toMillis() / 1000;
        }
        return onlineDuration;
    }

    public void setOnlineDuration(Long onlineDuration) {
        this.onlineDuration = onlineDuration;
    }

    public Long getOfflineDuration() {
        if (status == 0) {
            if (lastOfflineTime != null) {//如果有最近一次离线时间,就使用最近一次离线时间计算时间差
                offlineDuration = Duration.between(lastOfflineTime, LocalDateTime.now()).toMillis() / 1000;
            } else {//如果没有最近一次离线时间,就使用创建时间计算时间差
                offlineDuration = Duration.between(createTime, LocalDateTime.now()).toMillis() / 1000;
            }
        }
        return offlineDuration;
    }

    public void setOfflineDuration(Long offlineDuration) {
        this.offlineDuration = offlineDuration;
    }

    public LocalDateTime getLastOfflineTime() {
        return lastOfflineTime;
    }

    public void setLastOfflineTime(LocalDateTime lastOfflineTime) {
        this.lastOfflineTime = lastOfflineTime;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public String getLoginingUser() {
        return loginingUser;
    }

    public void setLoginingUser(String loginingUser) {
        this.loginingUser = loginingUser;
    }

    public BigDecimal getLat() {
        return lat;
    }

    public void setLat(BigDecimal lat) {
        this.lat = lat;
    }

    public BigDecimal getLng() {
        return lng;
    }

    public void setLng(BigDecimal lng) {
        this.lng = lng;
    }

    public String getUploadAuthCode() {
        return uploadAuthCode;
    }

    public void setUploadAuthCode(String uploadAuthCode) {
        this.uploadAuthCode = uploadAuthCode;
    }

    public LocalDateTime getOnlineStartTime() {
        return onlineStartTime;
    }

    public void setOnlineStartTime(LocalDateTime onlineStartTime) {
        this.onlineStartTime = onlineStartTime;
    }

    public LocalDateTime getLastHeartbeatTime() {
        return lastHeartbeatTime;
    }

    public void setLastHeartbeatTime(LocalDateTime lastHeartbeatTime) {
        this.lastHeartbeatTime = lastHeartbeatTime;
    }

    /**
     * 获取在线时间,转换为*小时*分*秒的字符串
     *
     * @return
     */
    public String getOnlineDurationStr() {
        return DateUtils.convertSecondsToHMS(getOnlineDuration());
    }

    /**
     * 获取离线时间,转换为*小时*分*秒的字符串
     *
     * @return
     */
    public String getOfflineDurationStr() {
        return DateUtils.convertSecondsToHMS(getOfflineDuration());
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "DetectPoint{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", pointNo='" + pointNo + '\'' +
                ", status=" + status +
                ", deviceType=" + deviceType +
                ", loginingUser='" + loginingUser + '\'' +
                ", detectDept='" + detectDept + '\'' +
                ", onlineDuration=" + onlineDuration +
                ", offlineDuration=" + offlineDuration +
                ", lastOfflineTime=" + lastOfflineTime +
                ", onlineStartTime=" + onlineStartTime +
                ", location='" + location + '\'' +
                ", lat=" + lat +
                ", lng=" + lng +
                ", uploadAuthCode='" + uploadAuthCode + '\'' +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }

}
